/*
 * Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
 *
 * Licensed under the Mulan PSL v2.
 * You can use this file according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of the License at
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
 * FOR MORE DETAILS.
 */

#pragma once

#include <vector>

#include "highfive/H5File.hpp"

#include "DataStructure/Common/Id.h"
#include "DataStructure/Common/Integer.h"
#include "DataStructure/Input/Constraint/IndexMappingData.h"

#include "DBManager/IRepository/Input/Constraint/IIndexMappingRepository.h"
#include "DBManager/Repository/HDF5/Base/SingleRepositoryBase.h"

template <>
inline HighFive::DataType HighFive::create_datatype<SG::DataStructure::FEM::IndexMappingData> ()
{
    HighFive::CompoundType compoundType = {
        { "GRID_INDEX", HighFive::create_datatype<SG::DataStructure::Common::I64> () },
        { "GLOBAL_DOF_INDEX", HighFive::create_datatype<SG::DataStructure::Common::I64[6]> (), SG::DBManager::FIELD_SIZE, true },
    };
    return compoundType;
}

SG_DBMANAGER_HDF5_NAMESPACE_OPEN
class IndexMappingRepository : public IIndexMappingRepository, public RepositoryBase
{
  public:
    explicit IndexMappingRepository (HDF5Database& database);

    void InitialDatasetInfo () override;

    /// @brief 使用vector批量添加数据
    /// @param entitys
    virtual SG::DataStructure::Common::Status Add (std::vector<SG::DataStructure::FEM::IndexMappingData>& entitys) override;

    /// @brief 获取获取所有索引的映射
    /// @return 局部到全局
    virtual SG::DataStructure::FEM::IndexMapping GetIndexMapping () override;

    /// @brief 获取总数
    /// @return
    virtual std::size_t Size () override;
};
SG_DBMANAGER_HDF5_NAMESPACE_CLOSE
